package BitManipulation;

public class _318_MaximumProductofWordLengths {
    public int maxProduct(String[] words) {
        if (words == null && words.length == 0) {
            return 0;
        }
        int len = words.length;
        int[] chas = new int[len];
        for (int i = 0; i < len; i++) {
            String word = words[i];
            for (int j = 0; j < word.length(); j++) {
                chas[i] += (1 << (word.charAt(j) - 'a'));
            }
        }
        int maxp = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j < len; j++) {
                if ((chas[i] & chas[j]) == 0) {
                    maxp = Math.max(maxp, words[i].length() * words[j].length());
                }
            }
        }
        return maxp;
    }
}
